package com.example.blog.srevice;

import com.example.blog.dao.ArticleMapper;
import com.example.blog.model.Articleinfo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 666
 * Date: 2023-07-31
 * Time: 16:18
 */
@Service
public class ArticleService {
    // 声明一个ArticleMapper类型的变量articleMapper
    @Resource
    private ArticleMapper articleMapper;

    // 根据uid获取文章列表
    public List<Articleinfo> getListByUid(int uid) {
        // 调用articleMapper的getListByUid方法，传入参数uid
        return articleMapper.getListByUid(uid);
    }

    // 删除文章
    public int del(Integer aid, int uid) {
        // 调用articleMapper的del方法，传入参数aid和uid
        return articleMapper.del(aid, uid);
    }

    // 添加文章
    public int add(Articleinfo articleinfo) {
        // 调用articleMapper的add方法，传入参数articleinfo
        return articleMapper.add(articleinfo);
    }

    // 根据aid和uid获取文章详情
    public Articleinfo getArticleByIdAndUid(int aid, int uid) {
        // 调用articleMapper的getArticleByIdAndUid方法，传入参数aid和uid
        return articleMapper.getArticleByIdAndUid(aid, uid);
    }

    // 根据aid更新文章
    public int update(Articleinfo articleinfo) {
        // 调用articleMapper的update方法，传入参数articleinfo
        return articleMapper.update(articleinfo);
    }

    // 根据aid获取文章详情
    public Articleinfo getDetail(int aid) {
        // 调用articleMapper的getDetailById方法，传入参数aid
        return articleMapper.getDetailById(aid);
    }

    // 根据uid获取文章总数
    public int getArtCountByUid(int uid) {
        // 调用articleMapper的getArtCountByUid方法，传入参数uid
        return articleMapper.getArtCountByUid(uid);
    }

    // 根据aid增加文章评论数
    public int incrementRCount(int aid) {
        // 调用articleMapper的incrementRCount方法，传入参数aid
        return articleMapper.incrementRCount(aid);
    }

    // 根据aid获取文章列表
    public List<Articleinfo> getListByPage(int psize, int offset) {
        // 调用articleMapper的getListByPage方法，传入参数psize和offset
        return articleMapper.getListByPage(psize, offset);
    }

    // 根据aid获取文章总数
    public int getCount(){
        // 调用articleMapper的getCount方法
        return articleMapper.getCount();
    }}